package com.example.food.controller;

import com.example.food.bean.Manager;
import com.example.food.repository.ManagerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Controller
public class ManagerController {

    @Autowired
    private ManagerRepository repository;

    //进入登录页面
    @RequestMapping("/")
    public String first() {
        return "login";
    }

    //登录验证
    @PostMapping("manager_login")
    public String login(@RequestParam("managerName") String managerName,
                        @RequestParam("managerPsw") String managerPsw,
                        Map<String, Object> map) {
        //根据管理员名查找
        Manager manager = new Manager();
        manager = repository.findByManagerName(managerName);
        //判断登录
        if (manager != null && manager.getManagerPsw().equals(managerPsw)) {
            return "home";
        } else {
            map.put("msg", "账号密码错误");
            return "login";
        }
    }


}
